<template>
    <div ref="body">
        <Form :label-width="120" inline>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.ssdc0009"></area-linkage>
            </Form-item>
            <Form-item label="发放年月">
                <DatePicker type="month" style="width:150px" v-model="queryParam.ssdc0001"
                            placeholder="请选择发放年月"  :editable="false"></DatePicker>
            </Form-item>
            <FormItem label="救助对象类别">
                <Select v-model="queryParam.ssdc0010" style="width: 200px" clearable>
                    <Option value="1010">城市最低生活保障对象</Option>
                    <Option value="1020">城市低保边缘家庭</Option>
                    <Option value="1030">农村最低生活保障对象</Option>
                    <Option value="1040">农村低保边缘家庭</Option>
                    <Option value="1050">城市单人保障对象</Option>
                    <Option value="1060">城市因病致贫保障对象</Option>
                    <Option value="1070">农村单人保障对象</Option>
                    <Option value="1080">农村因病致贫保障对象</Option>
                    <Option value="1090">农村建档立卡保障对象</Option>
                </Select>
            </FormItem>
                <Form-item label="户主姓名:">
                <Input v-model="queryParam.ssdc0003" placeholder="" style="width:200px"/>
            </Form-item>

            <Form-item label="身份证号:">
                <Input v-model="queryParam.ssdc0004" placeholder="" style="width:200px"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                  <Button type="primary"  icon="ios-undo" @click="exportDataExcel">两节救助花名册导出</Button>
                </span>
                <span style="float: right;">
                 <Button type="primary"  @click="searchQueryNew">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchResetNew">重置</Button>
                     </span>
            </Row>
        </Form>
        <div id="statistics">
            <span>两节救助查询统计:</span>
            <span> 总户数 [ {{statistics.familyNum}} ] 户</span>
            <span>  总救助金额 [ {{statistics.totalMoney}} ]  元</span>
        </div>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @cell-click="selectChange"
                       :data="tableData">
                <vxe-table-column type="radio" width="60" align="center" fixed="left"/>
                <vxe-table-column field="ssdc0001" title="救助年度" align="center" width="100" fixed="left"/>
                <vxe-table-column field="ssdc0009_name" title="属地区划" align="center" width="230" fixed="left"/>
                <vxe-table-column field="ssdc0003" title="被救助人姓名" align="center" width="90" fixed="left"/>
                <vxe-table-column field="ssdc0004" title="身份证号" align="center" width="160"/>
                <vxe-table-column field="ssdc0027_name" title="是否确认" align="center" width="80"/>
                <vxe-table-column field="ssdc0011" title="救助时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="ssdc0002_name" title="救助节日" align="center" width="160"/>
                <vxe-table-column field="ssdc0005_name" title="性别" align="center" width="80"/>
                <vxe-table-column field="ssdc0006" title="出生日期" align="center" width="120" :formatter="renderTime"/>
                <vxe-table-column field="ssdc0007" title="年龄" align="center" width="70" :formatter="formartAge"/>
                <vxe-table-column field="ssdc0008_name" title="健康状况" align="center" width="140"/>
                <vxe-table-column field="ssdc0010_name" title="救助对象类别" align="center" width="140"/>
                <vxe-table-column field="ssdc0012" title="标准救助金额" align="center" width="100"/>
                <vxe-table-column field="ssdc0013" title="增发救助金额" align="center" width="100"/>
                <vxe-table-column field="ssdc0014" title="总救助金额" align="center" width="100"/>
                <vxe-table-column field="ssdc0023" title="银行账号" align="center" width="160"/>
                <vxe-table-column field="ssdc0025_name" title="开户行" align="center" width="140"/>
                <vxe-table-column title="操作" align="center" width="140" fixed="right">
                    <template #default="{row}">
                        <Button type="default" @click="searchDetail(row)">查看详情</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {postAction} from '@/api/request'
    import DateFormat from '@/plugins/format.js'


    export default {
        name: "ss13003list",
        components: {},
        mixins: [CommonMixin],
        data() {
            return {
                exportFileName:'两节救助花名册',
                statistics: {
                    familyNum: 0,
                    totalMoney: 0,
                },
                queryParam: {
                    age_begin: null,
                    age_end: null,
                    ssdc0012_begin: null,
                    ssdc0012_end: null,
                    ssdc0013_begin: null,
                    ssdc0013_end: null,
                    ssdc0014_begin: null,
                    ssdc0014_end: null,
                },
                Loading: false,
                show: false,
                selectRow: null,
                url: {
                    list: "/api/ac/subsistence/ss18102Service/getPageList",
                    exportExcel: "/api/ac/subsistence/ss18102Service/exportData",
                },
                dictList: [],
            }
        },
        methods: {
            exportDataExcel () {
                let ssdc0001 = this.queryParam.ssdc0001;

                console.log(ssdc0001)
                if(ssdc0001 ==undefined||ssdc0001 == ''){
                    this.$Message.error("发放年月不能为空");
                    return;
                } else {
                    var time = this.queryParam.ssdc0001;
                    if (time) {
                        this.queryParam.ssdc0001 = this.DateFormat(time, 'YYYY')
                        this.queryParam.ssdc0011 = this.DateFormat(time, 'YYYY-MM')
                    }
                    this.exportFileName = "两节救助花名册" ;
                    this.exportExcel();
                    this.queryParam.ssdc0001 = this.DateFormat(time, 'YYYY-MM')
                }
            },
            dataConfirm() {
              //数据确认let
                let ssdc0010 = this.queryParam.ssdc0002;
                let ssdc0011 = this.queryParam.ssdc0011;
                if(ssdc0010 ==undefined){
                    this.$Message.error("请选择需要确认数据的救助对象类别");
                    return;
                }
                if(ssdc0011 == undefined){
                    this.$Message.error("请选择需要确认数据的救助年月");
                    return;
                }
                let param = {};
                let url = this.url.dataConfirm;
                param.ssdc0010 = ssdc0010;
                param.ssdc0011 = ssdc0011;
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$Message.success(res.data.data.msg);
                        this.loadData(1);
                    }
                }).finally(() => {
                    that.Loading = false;
                })
            },
            showHidden() {
                this.show = !this.show;
            },
            formartAge(h) {
                if (h.cellValue) {
                    return Number(h.cellValue);
                }
            },
            selectChange({row}) {
                this.$refs.xTree.setRadioRow(row);
                this.selectRow = row;
            },
            clearRadioRowEevnt() {
                this.selectRow = null
                this.$refs.xTree.clearRadioRow()
            },
            searchQueryNew() {
                var time = this.queryParam.ssdc0001;
                if (time) {
                    this.queryParam.ssdc0001 = this.DateFormat(time, 'YYYY')
                    this.queryParam.ssdc0011 = this.DateFormat(time, 'YYYY-MM')
                }
                var ssdc0006_time = this.queryParam.ssdc0006_time;
                if (ssdc0006_time) {
                    if (ssdc0006_time[0]) {
                        this.queryParam.ssdc0006_begin = this.DateFormat(ssdc0006_time[0], 'YYYY-MM-DD') + " 00:00:00";
                    }
                    if (ssdc0006_time[1]) {
                        this.queryParam.ssdc0006_end = this.DateFormat(ssdc0006_time[1], 'YYYY-MM-DD') + " 23:59:59";
                    }
                }
                var ssdc0011_time = this.queryParam.ssdc0011_time;
                if (ssdc0011_time) {
                    if (ssdc0011_time[0]) {
                        this.queryParam.ssdc0011_begin = this.DateFormat(ssdc0011_time[0], 'YYYY-MM-DD') + " 00:00:00";
                    }
                    if (ssdc0011_time[1]) {
                        this.queryParam.ssdc0011_end = this.DateFormat(ssdc0011_time[1], 'YYYY-MM-DD') + " 23:59:59";
                    }
                }
                this.clearRadioRowEevnt();
                this.loadData(1);
                this.queryParam.ssdc0001 = this.DateFormat(time, 'YYYY-MM')
            },
            searchResetNew() {
                this.queryParam = {};
                this.queryParam.age_begin = null;
                this.queryParam.age_end = null;
                this.queryParam.ssdc0012_begin = null,
                this.queryParam.ssdc0012_end = null,
                this.queryParam.ssdc0013_begin = null,
                this.queryParam.ssdc0013_end = null,
                this.queryParam.ssdc0014_begin = null,
                this.queryParam.ssdc0014_end = null,
                this.clearRadioRowEevnt();
                this.loadData(1);
            },
            loadData(arg) {
                if (arg == 1) {
                    this.pageNo = 1;
                }
                let that = this;
                that.Loading = true;
                let param = Object.assign({}, this.queryParam);
                let url = this.url.list;
                param.pageNo = this.pageNo;
                param.pageSize = this.pageSize;
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.tableData = res.data.data.results;
                        that.dataCount = res.data.data.totalRecord;
                        that.statistics.familyNum = res.data.data.params.familyNum;
                        that.statistics.totalMoney = res.data.data.params.totalMoney;
                    }
                }).finally(() => {
                    that.Loading = false;
                })
            }
            ,
            searchDetail(row) {
            }
            ,
            modalFormOk() {
                this.selectRow = null;
                // 新增/修改 成功时，重载列表
                this.loadData();
            },
        },

    }
</script>

<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ .ivu-form-item {
        margin-bottom: 10px;
    }

    #statistics {
        height: 50px;
        line-height: 50px;
        width: 100%;
        color: red;
        font-size: 16px;
    }

    #statistics span {
        padding-left: 10px;
        padding-right: 10px;
    }

</style>
